<template>
  <div class="content">
    <div class="details-head">
      <div class="head-img-group">
        <div class="head-tit">运单详情</div>
        <div class="head-ben-group">
          <el-button @click="back">返 回</el-button>
          <el-button type="primary"
                     plain
                     @click="submit(2)"> 保 存</el-button>
          <el-button v-if="!editCombine"
                     type="primary"
                     @click="submit(1)"> 调 度 </el-button>
          <el-popover v-if="!editCombine"
                      placement="top"
                      width="60px"
                      trigger="click"
                      style="margin: 0 10px">
            <div>
              <el-button type="text"
                         @click="toDetail(2)">数量拆单</el-button>
            </div>
            <div>
              <el-button type="text"
                         @click="toDetail(1)">线路拆单</el-button>
            </div>
            <el-button slot="reference">拆 单</el-button>
          </el-popover>
        </div>
      </div>
      <div class="line"></div>
    </div>
    <div class="wrap-box">
      <el-form ref="formInfo"
               :model="form"
               :rules="rules"
               label-width="100px">
        <simple-list :info="form"
                     :base="true"
                     class="mb20"
                     :config-data="[{ label: '合同编号:', type: 'contractNo', value: '' }]" />
        <el-row :gutter="20"
                style="margin-bottom: 20px">
          <el-col :span="12">
            <el-card>
              <descriptions v-if="form.customer"
                            :info="
                  Object.assign(
                    {},
                    form.customer,
                    form.fromAddress,
                    form.fromContact
                  )
                "
                            type="sender"
                            :icon-name="iconName"
                            :content="content"
                            :company="form.customer.showCustomerName " />
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="child_card">
              <descriptions v-if="form.consignee"
                            :info="
                  Object.assign(
                    {},
                    form.consignee,
                    form.toAddress,
                    form.toContact
                  )
                "
                            type="consign"
                            :company="form.consignee.consigneeName" />
            </el-card>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="发货时间"
                          prop="fromTime"
                          :rules="[{ required: true, message: '请选择或输入' }]">
              <el-date-picker v-model="form.fromTime"
                              align="left"
                              style="width: 100%"
                              type="datetime"
                              placeholder="请选择"
                              :clearable="false"
                              format="yyyy-MM-dd HH:mm"
                              :picker-options="fromTimePickerOptions"
                              :default-time="'00:00:00'"
                              popper-class="no-atTheMoment"
                              @change="changeTime(form.fromTime, 0)"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收货时间"
                          prop="toTime"
                          :rules="[{ required: true, message: '请选择或输入' }]">
              <el-date-picker v-model="form.toTime"
                              align="left"
                              type="datetime"
                              :clearable="false"
                              style="width: 100%"
                              placeholder="请选择"
                              format="yyyy-MM-dd HH:mm"
                              :default-time="'23:59:59'"
                              popper-class="no-atTheMoment"
                              :picker-options="pickerOptions"
                              @change="changeTime(form.toTime, 1)"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="时效天数"
                          :rules="[{ required: true, message: '请选择时效天数' }]"
                          prop="days">
              <el-select v-model="form.days"
                         style="width: 100%"
                         placeholder="请选择"
                         :disabled="!form.toTime && !form.fromTime"
                         @change="receivingDays">
                <el-option :value="0"
                           label="当天">当天</el-option>
                <el-option v-for="i in 30"
                           :key="i"
                           :value="i">{{ i }}天</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <transport v-if="status"
                   ref="transport"
                   :form-info="form"
                   :schedule="true" />
        <goods :records="form.goodsList"
               :total-data="form.waybillCache"
               @input="totalData" />
      </el-form>
      <dispatch-dialog v-if="dispatchVisible"
                       :id="id"
                       :form="form"
                       :dispatch-visible.sync="dispatchVisible"
                       :dispatch-type="'waybill'"
                       @selectCarrier="selectCarrier"></dispatch-dialog>
      <split-dialog v-if="splitVisible"
                    :id="form.id"
                    :split-visible.sync="splitVisible"></split-dialog>
      <SimpleTab v-show="isTrack"
                 title="跟踪信息">
        <Information :value="track" />
      </SimpleTab>
    </div>
  </div>
</template>
<script>
import descriptions from "@components/orderDetail/Descriptions.vue";
import SimpleList from "@components/orderDetail/SimpleList.vue";
import Transport from "@views/createOrder/createOrder/TransportSchedule.vue";
import Goods from "./components/Goods.vue";
import DispatchDialog from "@/components/public/DispatchDialog.vue";
import SplitDialog from "@/components/public/SplitOrderDialog.vue";
import SimpleTab from "@/components/basic/SimpleTab.vue";
import Information from "@/components/track/Information.vue";
import { transport, track } from "@/api/index";
import timeLinkage from "@/libs/timeLinkage";
import { returnCompareTime } from "@/libs/util.js";
import { FormData } from "./form.js";
import { mapState, mapActions } from "vuex";
import _ from 'lodash'

export default {
  name: "ScheduleDetail",
  components: {
    descriptions,
    Transport,
    DispatchDialog,
    Goods,
    SplitDialog,
    SimpleList,
    SimpleTab,
    Information
  },
  mixins: [timeLinkage],
  data () {
    return {
      rules: {},
      routerName: {
        //拆单路由名称
        1: "lineSplitting",
        2: "numSplitting"
      },
      id: null,
      splitVisible: false,
      orderDetails: {},
      dispatchVisible: false,
      form: new FormData(),
      status: false,
      addition: {
        weightAddition: 0,
        volumeAddition: 0,
        valueAddition: 0
      }, //补差
      systemBillObj: {
        billDateFlag: null, //是否已过关账期
        lastMonthDay: null,        // 关账期前一月的第一天
        sameMonthDay: null,        // 关账期当月的第一天
      },
      fromTimePickerOptions: {
        // 时间选择限制 发货时间
        disabledDate: (time) => {
          if (this.systemBillObj.billDateFlag) {
            // let fromTimeInit = returnCompareTime(
            //   new Date(this.$moment(this.form.fromTime).format("YYYY-MM-DD HH:mm:ss")),
            //   new Date(this.$moment(sameMonthDay).format("YYYY-MM-DD 23:59:59"))
            // ) ? this.form.fromTime : sameMonthDay;
            if (this.form.toTime) {
              return (
                time.getTime() <=
                new Date(
                  new Date(this.systemBillObj.sameMonthDay).setDate(
                    new Date(this.systemBillObj.sameMonthDay).getDate() - 1
                  )
                ).getTime() || time.getTime() > new Date(this.form.toTime).getTime()
              );
            } else {
              return (
                time.getTime() <=
                new Date(
                  new Date(this.systemBillObj.sameMonthDay).setDate(
                    new Date(this.systemBillObj.sameMonthDay).getDate() - 1
                  )
                ).getTime()
              );
            }
          } else if (this.form.toTime) {
            return (
              time.getTime() <=
              new Date(
                new Date(this.systemBillObj.lastMonthDay).setDate(
                  new Date(this.systemBillObj.lastMonthDay).getDate() - 1
                )
              ).getTime() || time.getTime() > new Date(this.form.toTime).getTime()
            )
          } else {
            return (
              time.getTime() <=
              new Date(
                new Date(this.systemBillObj.lastMonthDay).setDate(
                  new Date(this.systemBillObj.lastMonthDay).getDate() - 1
                )
              ).getTime()
            )
          }
        }
      },
      pickerOptions: {
        // 时间选择限制 收货时间
        disabledDate: (time) => {
          if (this.systemBillObj.billDateFlag) {
            let toTimeInit = returnCompareTime(
              new Date(this.$moment(this.form.fromTime).format("YYYY-MM-DD HH:mm:ss")),
              new Date(this.$moment(this.systemBillObj.sameMonthDay).format("YYYY-MM-DD 23:59:59"))
            ) ? this.form.fromTime : this.systemBillObj.sameMonthDay;
            return (
              time.getTime() <=
              new Date(
                new Date(toTimeInit).setDate(
                  new Date(toTimeInit).getDate() - 1
                )
              ).getTime()
            );
          } else if (this.form.fromTime) {
            return (
              time.getTime() <=
              new Date(
                new Date(this.form.fromTime).setDate(
                  new Date(this.form.fromTime).getDate() - 1
                )
              ).getTime()
            );
          } else {
            return (
              time.getTime() <=
              new Date(
                new Date(this.systemBillObj.lastMonthDay).setDate(
                  new Date(this.systemBillObj.lastMonthDay).getDate() - 1
                )
              ).getTime()
            );
          }
        },
        selectableRange: `00:00:00 - 23:59:59`
      },
      track: [], // 跟踪信息
      isTrack: false, // 跟踪信息标题显示
    };
  },
  computed: {
    close () {
      return [10, 20, 50, 60];
    },
    editCombine () {
      return this.$route.params?.editCombine
    },
    content () {
      const { customer } = this.form
      switch (customer?.showCustomerType) {
        case 0:
          return '线下';
        case 1:
          return '线上';
        default:
          return '';
      }
    },
    iconName () {
      const { customer } = this.form
      switch (customer?.showCustomerType) {
        case 0:
          return 'xianxia';
        case 1:
          return 'xianshang';
        default:
          return '';
      }
    },
    ...mapState({
      systemBillDateInfo: (state) => state.login.systemBillDateInfo || null,
      combineBatchEntry: (state) => state.combine.combineBatchEntry
    })
  },
  watch: {
    form: {
      deep: true,
      handler (val) {
        this.handlerChangeTime(val);
      }
    }
  },
  created () {
    this.id = this.$route.query?.id || this.$route.query?.waybillId;
    this.systemBillObj = { ...this.systemBillDateInfo };
    this.getDetail();
    this.trackInformation();
  },
  methods: {
    ...mapActions({
      saveCombineBatchEntry: "combine/saveCombineBatchEntry"
    }),
    toDetail (val) {
      if (val === 2 && this.form.waybillCache.totalQuantity < 2) {
        this.$message.warning("物品数量小于2，不能进行数量拆单！");
        return;
      }
      this.$router.push({
        name: this.routerName[val],
        query: { waybillId: this.id, detailFlag: 1 }
      });
    },
    // 选择承运方
    async selectCarrier (data) {
      this.form.waybillId = this.form.id;
      let postData = {
        ...data,
        waybillId: this.form.id,
        fromTime: this.form.fromTime,
        toTime: this.form.toTime,
        attachments: this.form.attachments,
        transportRequirement: this.form.transportRequirement,
        totalValue: this.form.waybillCache.calculateValue,
        totalVolume: this.form.waybillCache.calculateVolume,
        totalWeight: this.form.waybillCache.calculateWeight,
        desc: this.form.desc
      };
      let bindData = this.$refs.transport.$refs.bind.form || {};
      // if ([1, 2].includes(bindData.checkValue) && !bindData.deleteFlag) {
      //   if (
      //     bindData.thirdDeviceCode ||
      //     bindData.receiptAddress.wayCityCode ||
      //     bindData.receiptAddress.wayAddress
      //   ) {
      //     if (!bindData.thirdDeviceCode)
      //       return this.$message.warning("请选择电子回单！");
      //     if (!bindData.receiptAddress.wayCityCode)
      //       return this.$message.warning("请选择途径地区！");
      //     if (!bindData.receiptAddress.wayAddress)
      //       return this.$message.warning("请输入详细地址！");
      //   }
      // }
      if (bindData.checkValue === 3) {
        if (!bindData.secondDeviceCode)
          return this.$message.warning("请选择电子回单！");
        if (!bindData.secordReceiptAddress.wayCityCode)
          return this.$message.warning("请选择途径地区！");
        if (!bindData.secordReceiptAddress.wayAddress)
          return this.$message.warning("请输入详细地址！");

        if (bindData.isThirdShow) {
          if (!bindData.thirdDeviceCode)
            return this.$message.warning("请选择电子回单！");
          if (!bindData.receiptAddress.wayCityCode)
            return this.$message.warning("请选择途径地区！");
          if (!bindData.receiptAddress.wayAddress)
            return this.$message.warning("请输入详细地址！");
        }
      }
      postData.device = this.returnBindData(bindData);
      if (!postData.device.deviceCode) {
        postData.device.trackType = null;
      }
      let { code, message } = await transport.dispatch({ ...postData, ...this.addition });
      if (code === 0) {
        this.back();
      }
      this.$message[code === 0 ? "success" : "error"](message);
    },
    // 获取运单详情
    async getDetail () {
      let { data } = await transport.getDetail(this.id);
      this.form = { ...this.form, ...data };
      for (let key in this.form.waybillCache) {
        this.form.waybillCache[key] = Number(parseFloat(this.form.waybillCache[key]).toFixed(2));
      }
      this.addition = Object.assign(this.addition, this.form.waybillCache);
      if (!this.form.device.trackType) {
        this.form.trackType = 1;
        this.form.deviceCode = "";
      } else {
        this.form.trackType = this.form.device.trackType === 3 ? 1 : this.form.device.trackType;
        this.form.deviceCode =
          this.form.trackType == 1
            ? this.form.device.deviceCode
              ? this.form.device.deviceCode.substring(
                8,
                this.form.device.deviceCode.length
              )
              : null
            : this.form.device.deviceCode;
        let trackList = this.form.device.trackList;
        if (trackList && trackList.length > 0) {
          this.form.checkValue =
            trackList[0].transportType === 4 ? 3 : trackList[0].transportType;
          this.form.receiptAddress = {
            wayCity: "",
            wayCityCode: "",
            wayDistrict: "",
            wayDistrictCode: "",
            wayProvince: "",
            wayProvinceCode: "",
            wayAddress: ""
          };
          this.form.secordReceiptAddress = { ...this.form.receiptAddress };
          if ([1, 2].includes(this.form.checkValue)) {
            this.form.currentAddress = [
              { stationName: trackList[0].startPlace },
              { stationName: trackList[0].endPlace }
            ];
            this.form.secondDeviceCode = trackList[0].trackNo;
            if (this.form.checkValue == 1) {
              this.form.flyNo = trackList[0].trackNo;
              this.form.flyTime = trackList[0].startTime;
            } else if (this.form.checkValue == 2) {
              this.form.trainNum = trackList[0].trackNo;
              this.form.trainTime = trackList[0].startTime;
              this.form.trainForm = trackList[0].startPlace;
              this.form.trainTo = trackList[0].endPlace;
            }
            this.form.isThirdShow = false;
            this.form.deleteFlag = true;
            if (trackList.length > 1) {
              this.form.isThirdShow = true;
              this.form.deleteFlag = false;
              this.form.thirdDeviceCode = trackList[1].deviceNo.substring(
                8,
                trackList[1].deviceNo.length
              );
              this.form.receiptAddress = { ...trackList[1] };
            }
          } else {
            let arr = [];
            trackList.map((item, index) => {
              arr.push({ stationName: item.wayCity });
              if (index === 0) {
                this.form.secondDeviceCode = item.deviceNo.substring(
                  8,
                  item.deviceNo.length
                );
                this.form.secordReceiptAddress = { ...item };
                this.form.isThirdShow = false;
              } else {
                this.form.isThirdShow = true;
                this.form.thirdDeviceCode = item.deviceNo.substring(
                  8,
                  item.deviceNo.length
                );
                this.form.receiptAddress = { ...item };
              }
            });
            this.form.currentAddress = [...arr];
          }
        }
      }
      this.form.days = this.$moment(this.form.toTime).diff(
        this.$moment(this.form.toTime),
        "days"
      );
      this.status = true;
    },
    vaild () {
      this.$refs.formInfo.validate((valid) => {
        console.log("==========validate", valid)
      });
    },
    totalData (val, addition) {
      for (let key in addition) {
        this.addition[key + 'Addition'] = Number(addition[key]);
      }
      Object.assign(this.form.waybillCache, val);
    },
    submit: _.debounce(function (type) {
      this.$refs.formInfo.validate((valid) => {
        let transportForm = this.$refs.transport.form;
        this.$refs.transport.$refs.ruleForm.validate((val) => {
          if (valid && val) {
            this.form = { ...this.form, ...transportForm, fromTime: this.form.fromTime, toTime: this.form.toTime }
            // 重量校验 物品调整后的重量
            if (this.form.transportRequirement.chargeMode == 1 && Number(this.form?.waybillCache?.calculateWeight) <= 0) {
              if (this.form.transportRequirement.transportMode === 1) {
                return this.$message.error("计费模式为重量，物品总重量不能为空或小于0");
              } else if (
                this.form.transportRequirement.transportMode === 2 &&
                (this.form.transportRequirement?.onLoad === 1 || this.form.transportRequirement?.offLoad === 1)
              ) {
                return this.$message.error("计费模式为重量，物品总重量不能为空或小于0");
              }
            }
            // 体积校验 物品调整后的体积
            console.log("=======>waybillCache", this.form.waybillCache)
            if (this.form.transportRequirement.chargeMode == 2 && Number(this.form.waybillCache?.calculateVolume) <= 0) {
              if (this.form.transportRequirement.transportMode === 1) {
                return this.$message.error("计费模式为体积，物品总体积不能为空或小于0");
              } else if (
                this.form.transportRequirement.transportMode === 2 &&
                (this.form.transportRequirement?.onLoad === 1 || this.form.transportRequirement?.offLoad === 1)
              ) {
                return this.$message.error("计费模式为体积，物品总体积不能为空或小于0");
              }
            }
            // 总价值校验
            if (Number(this.form.waybillCache?.calculateValue) > 9999999999.99) {
              this.$message.error("总价值不能超过10位整数，请重新调整物品数量");
              return;
            }

            if (this.form.transportRequirement.transportMode === 2) {
              if (
                this.form.waybillCache.calculateWeight >
                Number(this.form.transportRequirement.vehicleWeight) *
                1000 *
                this.form.transportRequirement.vehicleCount ||
                this.form.waybillCache.totalVolume >
                this.form.transportRequirement.vehicleVolume *
                this.form.transportRequirement.vehicleCount
              ) {
                this.$confirm("货物超载，是否继续", {
                  title: "提示",
                  type: "warning"
                })
                  .then(() => {
                    this.handleSubmit(type);
                  })
                  .catch((err) => {
                    console.log("err", err)
                  });
              } else {
                this.handleSubmit(type);
              }
            } else {
              this.handleSubmit(type);
            }
          } else {
            return false;
          }
        });
      });
    }, 600),

    handleSubmit (type) {
      switch (type) {
        case 1:
          this.handlerDispatch();
          break;
        case 2:
          this.save();
          break;
      }
    },
    handlerDispatch () {
      if (this.close.includes(this.form.closeStatus)) {
        return this.$message({ type: 'warning', message: `运单有关单待办需要处理，暂不能操作` })
      } else if (this.form.billDayStatus) {
        this.$confirm(`运单已过关账期，双方不能再报价，是否确定继续操作?`,
          "提示",
          {
            confirmButtonText: "调度",
            type: "warning",
            closeOnClickModal: false
          }).then(() => {
            this.dispatchVisible = true; //调度
          });
      } else {
        this.dispatchVisible = true; //调度
      }
    },
    async save () {
      this.form.waybillId = this.id;
      let { totalVolume, totalWeight, totalValue } = this.form?.waybillCache;
      this.form.totalVolume = totalVolume;
      this.form.totalWeight = totalWeight;
      this.form.totalValue = totalValue;

      this.form.transportRequirement.pick =
        this.form.transportRequirement.pick || 0;
      this.form.transportRequirement.deliver =
        this.form.transportRequirement.deliver || 0;
      this.form.transportRequirement.chargeMode =
        this.form.transportRequirement.chargeMode || 2;
      this.form.transportRequirement.pricingUnit =
        this.form.transportRequirement.pricingUnit || 3;

      let bindData = this.$refs.transport.$refs.bind.form || {};
      // if ([1, 2].includes(bindData.checkValue) && !bindData.deleteFlag) {
      //   if (
      //     bindData.thirdDeviceCode ||
      //     bindData.receiptAddress.wayCityCode ||
      //     bindData.receiptAddress.wayAddress
      //   ) {
      //     if (!bindData.thirdDeviceCode)
      //       return this.$message.warning("请选择电子回单！");
      //     if (!bindData.receiptAddress.wayCityCode)
      //       return this.$message.warning("请选择途径地区！");
      //     if (!bindData.receiptAddress.wayAddress)
      //       return this.$message.warning("请输入详细地址！");
      //   }
      // }
      if (bindData.checkValue === 3) {
        if (!bindData.secondDeviceCode)
          return this.$message.warning("请选择电子回单！");
        if (!bindData.secordReceiptAddress.wayCityCode)
          return this.$message.warning("请选择途径地区！");
        if (!bindData.secordReceiptAddress.wayAddress)
          return this.$message.warning("请输入详细地址！");

        if (bindData.isThirdShow) {
          if (!bindData.thirdDeviceCode)
            return this.$message.warning("请选择电子回单！");
          if (!bindData.receiptAddress.wayCityCode)
            return this.$message.warning("请选择途径地区！");
          if (!bindData.receiptAddress.wayAddress)
            return this.$message.warning("请输入详细地址！");
        }
      }
      this.form.device = this.returnBindData(bindData);
      if (!this.form.device.deviceCode) {
        this.form.device.trackType = null;
      }
      /***** 清除不需要的参数 *****/
      for (let key in this.form) {
        let arr = [
          "customer", "consignee", "waybillCache", "goodsList", "updateBy", "createBy", "secordReceiptAddress", "receiptAddress",
          "toInfo", "toContact", "toAddress", "fromInfo", "fromContact", "fromAddress",
          "deviceCode", "trackType"
        ];
        if (arr.includes(key)) {
          Reflect.deleteProperty(this.form, key)
        }
      }
      let { code, message } = await transport.update(
        {
          ...this.form,
          ...this.addition
        }
      );
      this.$message[code === 0 ? "success" : "error"](message);
      if (code === 0) {
        if (this.editCombine) {
          const { tableData, page, pageSize, index, form } = this.combineBatchEntry
          if (this.combineBatchEntry?.tableData?.length) {
            if (this.form.transportRequirement.transportMode === 2) {
              this.form.transportRequirement.pick = 0
              this.form.transportRequirement.deliver = 0
            }
            let i = (page - 1) * pageSize + index;
            tableData[i] = {
              ...tableData[i],
              fromTime: this.form.fromTime,
              toTime: this.form.toTime,
              calculateWeight: Number((this.addition.totalWeight + this.addition.weightAddition).toFixed(2)),
              calculateVolume: Number((this.addition.totalVolume + this.addition.volumeAddition).toFixed(2)),
              totalWeight: this.addition.totalWeight,
              totalVolume: this.addition.totalVolume,
              transportRequirement: {
                ...this.form.transportRequirement,
                transportModeDesc: this.form.transportRequirement.transportMode === 1 ? '零担' : '整车'
              },
              ...this.form.transportRequirement,
              ...this.form.device,
              device: this.form.device
            }
          }
          this.saveCombineBatchEntry({ form, index, page, pageSize, tableData })
          this.back();
        } else {
          this.getDetail();
          this.trackInformation();
        }
      }
    },
    returnBindData (bindData) {
      let deviceCode =
        bindData.trackType === 1
          ? bindData.deviceCode
            ? `35160808${bindData.deviceCode}`
            : null
          : bindData.deviceCode;
      let transportsArr = [];
      if (bindData.checkValue === 1 && bindData.flyNo) {
        transportsArr.push({
          sequence: "1",
          transportType: 1,
          startPlace: bindData.currentAddress[0].stationName,
          endPlace: bindData.currentAddress[1].stationName,
          transitNo: bindData.flyNo,
          startTime: bindData.flyTime,
          type: "AIRPLANE_TYPE"
        });
        // if (bindData.receiptAddress.wayDistrictCode) {
        transportsArr.push({
          ...bindData.receiptAddress,
          sequence: "2",
          transportType: 4,
          deviceCode: bindData.thirdDeviceCode ? `35160808${bindData.thirdDeviceCode}` : deviceCode,
          type: "DEVICE_TYPE"
        });
        // }
      } else if (bindData.checkValue === 2 && bindData.trainNum) {
        transportsArr.push({
          sequence: "1",
          transportType: 2,
          startPlace: bindData.trainForm,
          endPlace: bindData.trainTo,
          transitNo: bindData.trainNum,
          startTime: bindData.trainTime,
          type: "TRAIN_TYPE"
        });
        // if (bindData.receiptAddress.wayDistrictCode) {
        transportsArr.push({
          ...bindData.receiptAddress,
          sequence: "2",
          transportType: 4,
          deviceCode: bindData.thirdDeviceCode ? `35160808${bindData.thirdDeviceCode}` : deviceCode,
          type: "DEVICE_TYPE"
        });
        // }
      } else if (bindData.checkValue === 3) {
        transportsArr.push({
          ...bindData.secordReceiptAddress,
          sequence: "1",
          transportType: 4,
          deviceCode: `35160808${bindData.secondDeviceCode}`,
          type: "DEVICE_TYPE"
        });
        if (bindData.isThirdShow) {
          transportsArr.push({
            ...bindData.receiptAddress,
            sequence: "2",
            transportType: 4,
            deviceCode: `35160808${bindData.thirdDeviceCode}`,
            type: "DEVICE_TYPE"
          });
        }
      }
      return {
        deviceCode,
        trackType: bindData.trackType,
        transports: [...transportsArr]
      };
    },
    back () {
      this.$router.back();
    },
    // 跟踪信息
    async trackInformation () {
      const { id, waybillId } = this.$route.query;
      let type = 'waybill'
      let { code, data } = await track.information(waybillId || id, type);
      if (code === 0 && data.length) {
        data.map(item => {
          item.timestamp = item.message.slice(0, item.message.indexOf('，'))
          item.date = item.message.slice(item.message.indexOf('，') + 1, item.message.lastIndexOf('】') + 1)
          if (item.message.indexOf('】') == -1) {
            item.content = item.message.slice(item.message.indexOf('，') + 1)
          } else {
            item.content = item.message.slice(item.message.lastIndexOf('】') + 1)
          }
        })
        this.track = data
        this.isTrack = true
      }
    },
  }
};
</script>
<style lang="scss" scoped>
.content {
  background: var(--prev-bg-white);
  padding: 20px;
  position: relative;
}
.wrap-box {
  position: relative;
  // width: 100%;
  height: 82vh;
  padding: 0 20px;
  overflow-y: auto;
}
.box {
  padding: 40px 0px 10px;
}

.details-head {
  width: 100%;
  height: 60px;
  background: var(--prev-bg-white);
  position: sticky;
  top: 0;
  z-index: 99;
}
.details-head img {
  height: 60px;
  z-index: -1;
  /* width: inherit;
  max-width: 1200px; */
}
.line {
  width: 100%;
  border-bottom: 4px solid var(--prev-icon-color-orange);
  position: absolute;
  top: 56px;
}
.head-ben-group {
  position: absolute;
  top: 14px;
  right: 14px;
}
.head-tit {
  position: absolute;
  top: 0;
  left: 15px;
  font-size: 20px;
  color: var(--prev-color-text-black);
  font-weight: 500;
  line-height: 60px;
}
.hide {
  display: none !important;
}
.display {
  display: inline-block !important;
}
</style>